<template>
  <li class="item">
    <!-- 头像 -->
    <div class="left">
      <div class="avatar">
        <img :src="item.aut_photo" alt="" />
      </div>
    </div>
    <!-- 中间的内容 -->
    <div class="mid">
      <div class="username">{{ item.aut_name }}</div>
      <div class="context">{{ item.content }}</div>
      <div class="bottom">
        <div class="time">{{ item.pubdate | findTime }}</div>
        <div class="reply" @click="replayCom(item)">回复 {{ count }}</div>
      </div>
    </div>
    <!-- 点赞 -->
    <div class="right">
      <div class="like">
        <van-icon
          class="myIcon"
          name="like-o"
          v-if="!like"
          @click="likeCom(item)"
        />
        <van-icon
          class="myIcon active"
          name="like"
          v-else-if="like"
          @click="dislikeCom(item)"
        />
        {{ item.like_count }}
      </div>
    </div>
  </li>
</template>

<script>
export default {
  name: 'commentItem',
  props: ['item', 'index'],
  data () {
    return {
      like: false,
      count: 0
    }
  },
  created () {
    this.count = this.item.reply_count
  },
  methods: {
    replayCom (item) {
      this.$emit('replayCom', item)
      console.log(this.index)
    },
    likeCom (item) {
      this.$emit('likeCom', item)
      this.like = true
      this.item.like_count += 1
    },
    dislikeCom (item) {
      this.$emit('dislikeCom', item)
      this.like = false
      this.item.like_count -= 1
    }
  }
}
</script>

<style lang="less" scoped>
.item {
  padding: 20px 0;
  display: flex;
  font-size: 12px;
  border-bottom: 1px solid #e8e8e8;
  color: #222222;
  .left {
    margin-right: 10px;
    .avatar {
      width: 50px;
      height: 50px;
      border-radius: 50%;
      overflow: hidden;
      img {
        height: 100%;
        width: 100%;
      }
    }
  }
  .mid {
    padding-top: 2px;
    flex: 1;
    .username {
      color: #416699;
      font-size: 14px;
    }
    .context {
      padding: 10px 0;
      font-size: 16px;
    }
    .bottom {
      display: flex;
      align-items: center;
      .time {
        margin-right: 10px;
      }
      .reply {
        padding: 6px 12px;
        background-color: #f4f5f6;
        border-radius: 8px;
      }
    }
  }
  .right {
    box-sizing: border-box;
    padding-left: 5px;
    width: 50px;

    .like {
      display: flex;
      align-items: center;
      .myIcon {
        font-size: 18px;
        margin-right: 2px;
      }
      .active {
        color: #e22829;
      }
    }
  }
}
</style>
